package com.example.controller;

import com.example.common.Result;
import com.example.entity.Course;
import com.example.service.CourseService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//标注这是一个接口
@RestController
//一级路径
@RequestMapping("/course")
public class CourseController {
    @Resource//获取courseMapper
    private CourseService courseService;

    @GetMapping("/selectPage")//标注这是一个查询接口
    //查询接口
    public Result selectPage(@RequestParam(defaultValue="1") Integer pageNum,
                             @RequestParam(defaultValue="5") Integer pageSize,
                             Course course){
        PageInfo<Course> pageInfo = courseService.selectPage(pageNum,pageSize,course);
        return Result.success(pageInfo);//返回课程列表和总数
    }
    //新增课程信息
    @PostMapping("/add")
    public Result add(@RequestBody Course course) {
        courseService.add(course);
        return Result.success();
    }
    //更新课程
    @PutMapping("/update")
    public Result update(@RequestBody Course course) {
        courseService.updateById(course);
        return Result.success();
    }
    //删除课程
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        courseService.deleteById(id);
        return Result.success();
    }
}
